/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#ifndef BIO_SEQ_DATABASE_H
#define BIO_SEQ_DATABASE_H

#include "BioDefs.h"

#include <QtCore/QString>
#include <QtCore/QHash>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>

#include "SeqRecord.h"

namespace Bio {

class Sequence;
class SeqParser;
class SeqFeature;
class SeqLocation;
class SqlInsertBuilder;
class Progress;
class DbXrefInsertBuilder;

class BIO_EXPORT SeqDatabase {
	friend class SqlServer;
public:
	SeqDatabase();
	SeqDatabase( const SeqDatabase &db );
	~SeqDatabase();

	bool	isValid() const;

	bool	load( SeqParser *parser );
	bool	load( SeqRecord &record );

	SeqRecord	getRecord( int bioentryId );
	SeqRecord	getRecordByAccession( const QString &accession );

	QList<SeqRecord>	getRecordsForTaxon( int taxonId );

	QString	getAnnotation( const QString &key ) const;
	void	setAnnotation( const QString &key, const QString &value );

	QMapIterator<QString, QString>	getAnnotationIterator() const;

	SeqDatabase&	operator=( const SeqDatabase &db );

protected:

	SeqDatabase( const QString &name, int bioID, SqlServer *server );

private:

	class SeqDatabaseData;
	QSharedDataPointer<SeqDatabaseData>	m_data;
};

}; // Bio

#endif // BIO_SEQ_DATABASE_H